#include <ximera/graphics/ogre/particlesystem.hpp>
#include <ximera/graphics/ogre/ogre.hpp>
#include <ximera/common/utils.hpp>

namespace ximera { namespace graphics { namespace ogre
{
    ParticleSystem::ParticleSystem(Ogre::SceneManager* ogreSceneManager, String const& name, String const& templateName)
        : IParticleSystem(name),
          _ogreSceneManager(ogreSceneManager)
    {
        XIMERA_ASSERT_DEF(ogreSceneManager);

        try 
        {
            _ogreParticleSystem = ogreSceneManager->createParticleSystem(
                string_util::wstr2str(name), string_util::wstr2str(templateName));
        }
        catch (Ogre::Exception& e)
        {
            XIMERA_THROW_OGRE_EXCEPTION(e);
        }
    }

    ParticleSystem::~ParticleSystem()
    {
        _ogreSceneManager->destroyParticleSystem(_ogreParticleSystem);
    }

    bool ParticleSystem::visible() const
    {
        return _ogreParticleSystem->getVisible();
    }

    void ParticleSystem::visible(bool vis)
    {
        _ogreParticleSystem->setVisible(vis);
    }

    String ParticleSystem::materialName() const
    {
        return string_util::str2wstr(_ogreParticleSystem->getMaterialName());
    }
    
    void ParticleSystem::materialName(String const& name)
    {
        _ogreParticleSystem->setMaterialName(string_util::wstr2str(name));
    }

    void ParticleSystem::setDefaultDimensions(Real width, Real height)
    {
        _ogreParticleSystem->setDefaultDimensions(width, height);
    }

    Real ParticleSystem::speedFactor()
    {
        return _ogreParticleSystem->getSpeedFactor();
    }
    
    void ParticleSystem::speedFactor(Real factor)
    {
        _ogreParticleSystem->setSpeedFactor(factor);
    }

    bool ParticleSystem::castShadows() const
    {
        return _ogreParticleSystem->getCastShadows();
    }

    void ParticleSystem::castShadows(bool casts)
    {
        _ogreParticleSystem->setCastShadows(casts);
    }
}}}